package com.lc.user.express.ordering;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.lc.user.express.BaseSecondActivity;
import com.lc.user.express.R;
import com.lc.user.express.app.AppContext;
import com.lc.user.express.httpserver.GetGoodsPay;
import com.lc.user.express.my.LoginActivity;
import com.lc.user.express.utils.GetToast;
import com.lc.user.express.utils.PublicMethod;
import com.zcx.helper.http.AsyCallBack;


/**
 * Created by Administrator on 2016/3/23. 家具支付
 */
public class FuniturePayActivity extends BaseSecondActivity {
    private EditText et_name;
    private EditText et_mobile;
    private EditText et_addr;
    private EditText et_style;
    private EditText et_beizhu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_funiture_pay);
        setTitle(getIntent().getStringExtra("title"));
        initView();
    }

    private void initView() {
        ((TextView) findViewById(R.id.tv_public)).setOnClickListener(this);
        et_name = (EditText) findViewById(R.id.et_name);
        et_mobile = (EditText) findViewById(R.id.et_mobile);
        et_addr = (EditText) findViewById(R.id.et_addr);
        et_style = (EditText) findViewById(R.id.et_style);
        et_beizhu = (EditText) findViewById(R.id.et_beizhu);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.tv_public:
                if (ifCommit()) {
                    commit();
                }
                break;
        }
    }

    private boolean ifCommit() {
        if (TextUtils.isEmpty(et_name.getText().toString().trim())) {
            GetToast.useString(cnt, "请填写姓名");
            return false;
        }
        if (!PublicMethod.isMobilePhone(et_mobile.getText().toString().trim())) {
            GetToast.useString(cnt, "请填写正确的电话号码");
            return false;
        }
        if (TextUtils.isEmpty(et_addr.getText().toString().trim())) {
            GetToast.useString(cnt, "请填写详细地址");
            return false;
        }
        if (!AppContext.myPreferences.getIsLogin()) {
            show(LoginActivity.class, LoginActivity.TYPE_LOGIN);
        }
        if (TextUtils.isEmpty(et_style.getText().toString().trim())) {
            GetToast.useString(cnt, "款式和型号不能为空");
            return false;
        }
        return true;
    }

    private void commit() {
        GetGoodsPay getGoodsPay = new GetGoodsPay(et_name.getText().toString().trim(), et_mobile.getText().toString().trim()
                , et_addr.getText().toString().trim(), AppContext.myPreferences.getUid(), getIntent().getStringExtra("goodsid"), "1", "1", new AsyCallBack<Object>() {
            @Override
            public void onSuccess(String toast, int type, Object o) throws Exception {
                GetToast.useString(cnt, toast);
                finish();
            }
        });
        getGoodsPay.userid = AppContext.myPreferences.getUid();
        getGoodsPay.name = et_name.getText().toString().trim();
        getGoodsPay.mobile = et_mobile.getText().toString().trim();
        getGoodsPay.address = et_addr.getText().toString().trim();
        getGoodsPay.goodid = getIntent().getStringExtra("goodsid");
        getGoodsPay.content= et_style.getText().toString();
        getGoodsPay.type= et_style.getText().toString();
        getGoodsPay.execute(cnt);
    }
}
